<template>
  <div class="share">
    <Ready :isReady="isReady" @closeReady="choseR" v-if="isReady"/>
    <Ruler :isRuler="isRuler" @closeRuler="chosePanel"/>
    <div class="flower-panel"></div>
    <div class="wave-footer"></div>
    <div class="container">
      <header class="animated fadeInDown"></header>
      <article class="title">
        <p>选取一道菜，找食材去咯</p>
      </article>
      <ul class="foods">
        <li v-for="(item,index) of foodList" :key="index">
          <img
            :src="item.foodImgUrl"
            @click.passive.stop.once="chooseFoodFunc(item)"
            class="animated bounceIn"
            :alt="item.code"
          >
          <span>{{item.foodName}}</span>
        </li>
      </ul>
      <footer>
        <p class="ruler-btn" @click.passive.stop="showRuler">
          <span>活动规则</span>
          <i class="wenhao"></i>
        </p>
      </footer>
    </div>
  </div>
</template>
<script>
import Ready from '@/components/Ready'
import Ruler from '@/components/Ruler'
import ruler from '@/mixins/ruler'
import { getFoods, chooseFood } from '@/axios/api'
export default {
  data() {
    return {
      isReady: true,
      isRec: true,
      hadRec: false,
      foodList: [],
      //   foodImg: require('@/assets/images/meicai/meicai.png'),
    }
  },
  components: { Ruler, Ready },
  mixins: [ruler],
  created() {
    Promise.all([getFoods()]).then(rs => {
      console.log(rs[0].res);
      [rs[0].res[1], rs[0].res[3]] = [rs[0].res[3], rs[0].res[1]];
      this.foodList = rs[0].res;
    })
  },
  mounted() {
  },
  methods: {
    //选择食物
    chooseFoodFunc(item) {
      chooseFood({ fd: item.code }).then(rs => {
        console.log(rs);
        localStorage.setItem('food', JSON.stringify(item));
        this.$router.replace({ name: 'make', query: {} })
      })

    },
    choseR(e) {
      this.isReady = e;
    }
  },
}
</script>

<style lang="less" scoped>
.share {
  width: 100%;
  height: 100%;
  font-size: 24px;
  background: url("../assets/images/wave.png");
  background-size: 100% auto;
  .flower-panel {
    position: fixed;
    z-index: 333;
    width: 100%;
    height: 100%;
    font-size: 24px;
    background: url("../assets/images/bg.png") no-repeat;
    background-size: 100% auto;
  }
  .wave-footer {
    position: fixed;
    bottom: 0;
    z-index: 333;
    width: 640px;
    height: 65px;
    background: url("../assets/images/flow.png") no-repeat;
    background-size: 640px 65px;
  }
  .container {
    position: relative;
    z-index: 666;
    width: 100%;
    height: 100%;
    header {
      width: 100%;
      height: 192px;
      background: url("../assets/images/share-panel.png") no-repeat;
      background-size: 100% auto;
    }
    article {
      margin-top: 23px;
      text-align: center;
      line-height: 1.5em;
      font-size: 34px;
      font-weight: bold;
      color: #eed993;
    }
    .foods {
      display: flex;
      justify-content: center;
      align-items: center;
      flex-wrap: wrap;
      margin: 10px auto;
      li {
        display: flex;
        padding: 20px;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        flex-wrap: wrap;
        span {
          font-size: 28px;
          color: #fff;
        }
        img {
          align-self: center;
          width: 240px;
          margin-bottom: 20px;
        }
      }
    }
    footer {
      .research {
        margin: 0 auto;
        width: 505px;
        height: 96px;
        background: url("../assets/images/share-btns.png") no-repeat;
        background-size: 505px 220px;
      }
      .help-research {
        margin: 20px auto;
        width: 505px;
        height: 96px;
        background: url("../assets/images/share-btns.png") no-repeat 0 -120px;
        background-size: 505px 220px;
      }
      .had-research {
        width: 504px;
        height: 104px;
        background: url("../assets/images/had-rec.png") no-repeat;
        background-size: 504px 104px;
      }
    }
    .ruler-btn {
      margin: 0 auto;
      text-align: center;
      color: #faf3e7;
      font-size: 24px;
      display: flex;
      justify-content: center;
      justify-items: center;
      span {
        align-self: center;
      }
      .wenhao {
        align-self: center;
        margin: auto 10px;
        width: 22px;
        height: 22px;
        background: url("../assets/images/wenhao.png") no-repeat;
        background-size: 100% auto;
      }
    }
  }
}
</style>
